<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Deferred</title>
</head>

<body>
    <script src="../src/ajax.deferred.js"></script>
    <script>
        // 结合使用
        Ajax({
            method: 'get',
            url: '/base/get',
            params: {
                foo: {
                    bar: 'baz'
                }
            },
            before: function (config) {
                console.log('before-1', config)
            },
            after: function (response) {
                console.log('after-1', response)
            },
        }).done(function (response) {
            console.log('done-1', response)
        }).fail(function (error) {
            console.log('fail-1', error)
        });
        //取消使用
        var http1 = Ajax({
            method: 'post',
            url: '/base/post',
            data: {
                a: 1,
                b: 2
            },
            before: function (config) {
                console.log('before-2', config)
                // return false; 
            },
            after: function (response) {
                console.log('after-2', response)
            },
        }).done(function (response) {
            console.log('done-2', response)
        }).fail(function (error) {
            console.log('fail-2', error)
        });
        http1.abort();
        // 错误使用
        var http2 = Ajax({
            method: 'get',
            url: '/error/get',
            before: function (config) {
                console.log('before-3', config)
            },
            after: function (response) {
                console.log('after-3', response)
            },
            error: function(error) {
                console.log('error-3', error)
            }
        }).done(function (response) {
            console.log('done-3', response)
        }).fail(function (error) {
            console.log('fail-3', error)
        });
        // post方法使用
        Ajax.post('/base/post', { a: 1, b: 2 }, function(response){
            console.log('post-after-4', response)
        }).done(function (response) {
            console.log('done-4', response)
        })
    </script>
</body>

</html>